package cn.wolfcode.rocketmq._03_type;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class Consumer {
    public static void main(String[] args) throws Exception{
        //创建一个拉取消息的消费者对象
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("consumer-type");
        //设置名字地址
        consumer.setNamesrvAddr("localhost:9876");
        //启动消费者
        consumer.start();
        //拉取消息
        PullResult pull = consumer.pull(new MessageQueue("03-type","broker-a",2),"*",0,10);
        List<MessageExt> list = pull.getMsgFoundList();
        for (MessageExt messageExt : list){
            System.out.println("信息内容为:" + new String(messageExt.getBody()));
        }
        consumer.shutdown();
    }
}
